package com.nulldev.util.web.YouTubeExtractor.testing;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.data.Arrays.maps.FastMaps;
import com.nulldev.util.internal.testing.TestManager;
import com.nulldev.util.io.FastIO.FastIO;
import com.nulldev.util.scripting.ScriptAPI.nScripting;
import com.nulldev.util.web.YouTubeExtractor.YouTubeExtractor;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.DeciphererTests;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.DeciphererV9Tests;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.ExtractionTests;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.ExtractorTests;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.FrontpageTests;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.SignatureExtractorTests;
import com.nulldev.util.web.YouTubeExtractor.testing.tests.TrendingTests;

public class YTETestSuite extends TestManager {

	private static final String VIDEO_ID_STANDARD = "k2qgadSvNyU";
	private static final String VIDEO_ID_CHAPTERS = "XwLakmNQzHY";

	public YTETestSuite() {
		super(FastMaps.uniMap(new Object[][]
			{
					/* Signature Extraction/Decipherer Generation */

					{ "signature-extractor-auto", new SignatureExtractorTests.SignatureExtractorAutoTest() },

					/* Decipherer Tests (v8) */

					{ "decipherer-v8-software", new DeciphererTests.V8DeciphererSoftwareTest() },
					{ "decipherer-v8-basejs", new DeciphererTests.V8DeciphererBaseJSTest() },
					{ "decipherer-v8-nashhorn",
							nScripting.isNashornInstalled() ? new DeciphererTests.V8DeciphererNashhornTest()
									: new DeciphererTests.V8DeciphererNashhornTest(true) },
					{ "decipherer-v8-rhino",
							nScripting.isRhinoInstalled() ? new DeciphererTests.V8DeciphererRhinoTest() : new DeciphererTests.V8DeciphererRhinoTest(true) },
					{ "decipherer-v8-graal",
							nScripting.isGraalJSInstalled() ? new DeciphererTests.V8DeciphererGraalTest() : new DeciphererTests.V8DeciphererGraalTest(true) },

					/* Decipherer Tests (v9) */

//			{"decipherer-v9-basejs", new DeciphererV9Tests.V9DeciphererBaseJSTest()},
					{ "decipherer-v9-nashhorn", nScripting.isNashornInstalled() ? new DeciphererV9Tests.V9DeciphererNashhornTest()
							: new DeciphererV9Tests.V9DeciphererNashhornTest(true) },
//			{"decipherer-v9-rhino", 
//						nScripting.isRhinoInstalled() ? new DeciphererV9Tests.V9DeciphererRhinoTest() :
//							new DeciphererV9Tests.V9DeciphererRhinoTest(true)},
//			{"decipherer-v9-graal", 
//								nScripting.isGraalJSInstalled() ? new DeciphererV9Tests.V9DeciphererGraalTest() :
//									new DeciphererV9Tests.V9DeciphererGraalTest(true)},

					/* Extractor Tests */

					{ "extractors-legacy-api", new ExtractorTests.ExtractorSpecTest("YTE.legacy.embedAPI", VIDEO_ID_STANDARD) },
					{ "extractors-legacy-nfee", new ExtractorTests.ExtractorSpecTest("YTE.legacy.nfee", VIDEO_ID_STANDARD) },
					{ "extractors-legacy-page", new ExtractorTests.ExtractorSpecTest("YTE.legacy.page", VIDEO_ID_STANDARD) },
					{ "extractors-next-embed", new ExtractorTests.ExtractorSpecTest("YTE.next.embedFEE", VIDEO_ID_STANDARD, true) },
					{ "extractors-next", new ExtractorTests.ExtractorSpecTest("YTE.next.nextFEE", VIDEO_ID_STANDARD) },
					{ "extractors-next-mt", new ExtractorTests.ExtractorSpecTest("YTE.next.nextFEE.MT", VIDEO_ID_STANDARD) },
					{ "extractors-next-rolling", new ExtractorTests.ExtractorSpecTest("YouTubeExtractor.NFEE_rolling_release", VIDEO_ID_STANDARD) },
					{ "extractors-ytapi", new ExtractorTests.ExtractorSpecTest("ytapi.native", VIDEO_ID_STANDARD) },
					{ "extractors-ytapi-rolling", new ExtractorTests.ExtractorSpecTest("ytapi.native-rolling", VIDEO_ID_STANDARD) },
					{ "extractors-vie", new ExtractorTests.ExtractorSpecTest("YTE.next.video_info_extractor", VIDEO_ID_STANDARD, true) },
					{ "extractors-invidious", new ExtractorTests.ExtractorSpecTest("YTE.third_party.invidious", VIDEO_ID_STANDARD) },

					/* Extractor Tests (Variant: EMBED_ONLY) */

					/* Extractor Tests (Variant: AGE_RESTRICTED, EMBED) */

					/* Extractor Tests (Variant: AGE_RESTRICTED, NON_EMBED) */

					/* Trending API Tests */

					{ "trending-fetch", new TrendingTests.YTETrendingTests() },

					/* Frontpage API Tests */

					{ "frontpage-fetch", new FrontpageTests.YTEFrontpageTests() },

					/* Extraction Working Tests */

					/*
					 * TODO for 2.2.x: Add tests that check if chapters, playlists and other items
					 * are being successfully extracted.
					 */

					{ "extraction-chapters", new ExtractionTests.ExtractorChapterTest(VIDEO_ID_CHAPTERS, "YTE.next.nextFEE") }

			}));
	}

	public static void main(String[] args) {
		JVM.println("=> Waiting for decipherer...");
		YouTubeExtractor.extractor.waitFor();
		JVM.println("=> Decipherer loaded.");
		final YTETestSuite ts = new YTETestSuite();
		ts.run();

		FastIO.get().flush();
		JVM.exit();
	}
}
